/***************************************************************************\
 * Copyright (C) by Keio University
 * Camera.cpp created in 05 2011.
 * Mail : fdesorbi@hvrl.ics.keio.ac.jp
 *
 * Camera.cpp is part of the HVRL Engine Project.
 *
 * The HVRL Engine Project is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * The HVRL Engine Project is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.	 If not, see <http://www.gnu.org/licenses/>.
 *
\***************************************************************************/

#include "hvrl/opengl/Camera.hpp"
#include <glm/gtx/quaternion.hpp>
#include <glm/gtc/matrix_transform.hpp>

Camera::Camera(void)
    : position(glm::vec3(0.0f,0.0f,0.0f)),
    front(glm::vec3(0.0f,0.0f,1.0f)),
    up(glm::vec3(0.0f,1.0f,0.0f)),
    right(glm::vec3(1.0f,0.0f,0.0f)),
    znear(0.01f),
    zfar(1000.0f),
    fovy(60.0f*0.0174532925199432f)
{

}

Camera::~Camera(void)
{

}

void Camera::translate(const glm::vec3& direction)
{
    this->position += direction;
}

void Camera::rotate(const float& roll, const float& pitch, const float& yaw)
{
    glm::quat q = glm::angleAxis(roll,this->front);
    this->right = glm::rotate(q,this->right);
    this->up = glm::rotate(q,this->up);

    q = glm::angleAxis(pitch,this->right);
    this->up = glm::rotate(q,this->up);
    this->front = glm::rotate(q,this->front);

    q = glm::angleAxis(yaw,this->up);
    this->right = glm::rotate(q,this->right);
    this->front = glm::rotate(q,this->front);
}

glm::mat4 Camera::getPerspective(const float& aspect) const
{
    return glm::perspective(
               this->fovy,
               aspect,
               this->znear,
               this->zfar);
}

glm::mat4 Camera::getLookAt(void) const
{
    return glm::lookAt(
               this->position + this->front,
               this->position,
               this->up);
}


